﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ICSharpCode.TextEditor.Document;

namespace SofireXSqlEntityGenerator.UI
{
    public partial class PreviewForm : Form
    {
        public PreviewForm()
        {
            InitializeComponent();
            this.Icon = MainForm.FormIcon;
            this.StartPosition = FormStartPosition.CenterParent;
            textEditorControl2.TextEditorProperties.Font = textEditorControl1.TextEditorProperties.Font = new Font("YaHei Consolas Hybrid", 10F);
            textEditorControl1.Document.HighlightingStrategy = HighlightingStrategyFactory.CreateHighlightingStrategy("C#");
            textEditorControl2.Document.HighlightingStrategy = HighlightingStrategyFactory.CreateHighlightingStrategy("XML");
            textEditorControl1.IsReadOnly = true;
            textEditorControl2.IsReadOnly = true;
        }
        public PreviewForm(string tableName, string entityCode)
            : this()
        {
            this.Text += "   -   " + tableName;
            textEditorControl1.Text = entityCode;
            textEditorControl1.TextChanged += textEditorControl1_TextChanged;
        }

        public string EditorText { get { return textEditorControl1.Text; } }
        public bool IsChanged { get; set; }

        void textEditorControl1_TextChanged(object sender, EventArgs e)
        {
            IsChanged = true;
        }

        public PreviewForm(string tableName, string entityCode, string xsqlCode)
            : this(tableName, entityCode)
        {
            textEditorControl2.Text = xsqlCode;
        }

        public void HideTab2()
        {
            tabPage1.Text = "Template";
            textEditorControl1.IsReadOnly = false;
            tabControl1.TabPages.Remove(tabPage2);
        }
    }
}
